package com.mes.web.controller.cb;

import com.mes.entity.cb.MaReturn;
import com.mes.entity.cb.Pages;
import com.mes.entity.tdd.ProcurementChuku;
import com.mes.service.cb.MaReturnService;
import com.mes.utils.CustomUtils;
import com.mes.utils.DateJsonValueProcessor;
import com.mes.utils.ResponseUtil;
import com.mes.utils.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @ClassName: MaReturnController
 * @Description: 资材退货
 * @Author cb
 * @Date 2018/4/13 16:10
 * @version 1.0
 */
@Controller
@RequestMapping("/return")
public class MaReturnController {

    @Resource
   private MaReturnService maReturnService;

    @RequestMapping("/maReturn_list")
    public void maReturn_list(HttpServletResponse response, String limit, String offset,String num) throws Exception {
        Pages pages = CustomUtils.pagings(limit, offset);

        if (StringUtil.isNotEmpty(num)) {
            pages.setNumber(num);
        }

        List<ProcurementChuku> list = maReturnService.maReturn_list(pages);
        int toat = maReturnService.maReturn_listTotal(pages);

        JSONObject jsonObject = new JSONObject();
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
        JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
        jsonObject.put("total", toat);
        jsonObject.put("rows", jsonArray);
        ResponseUtil.write(response, jsonObject);
    }

    @RequestMapping("/maReturnMx_list")
    public void maReturnMx_list(Long rid,HttpServletResponse response, String limit, String offset) throws Exception {
        Pages pages = CustomUtils.pagings(limit, offset);
        pages.setRid(rid);
        List<MaReturn> list = maReturnService.maReturnMx_list(pages);
        int total = maReturnService.maReturnMx_listTotal(pages);

        JSONObject jsonObject = new JSONObject();
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
        JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
        jsonObject.put("total", total);
        jsonObject.put("rows", jsonArray);
        ResponseUtil.write(response, jsonObject);
    }


}
